package org.feng.exception;

import feign.FeignException;
import org.feng.base.entity.Result;
import org.feng.base.enums.ErrorCode;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.security.auth.login.LoginException;

/**
 * @Author feng
 * @Date 2022/3/10 15:14
 * @Description TODO
 */
@RestControllerAdvice
public class ExceptionHandlers {

    @ExceptionHandler(ServiceException.class)
    public Result<String> exception(ServiceException e) {
        e.printStackTrace();
        return Result.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(FeignException.class)
    public Result<String> exception(FeignException e) {
        e.printStackTrace();
        return Result.error(ErrorCode.TRANSFER_SERVICE);
    }

    /**
     * 调用服务失败
     *
     * @param e
     * @return
     */
    @ExceptionHandler(TransferServiceException.class)
    public Result<String> exception(TransferServiceException e) {
        e.printStackTrace();
        return Result.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(LoginException.class)
    public Result<String> exception(LoginException e) {
        e.printStackTrace();
        return Result.error(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result<String> exception(Exception e) {
        e.printStackTrace();
        return Result.error(e.getMessage());
    }
}
